package com.dao.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.bean.Suggestion;
import com.dao.SuggestionDao;
import com.util.LoggerUtil;

@Component
public class SuggestionDaoImpl implements SuggestionDao{
	public static Logger logger=Logger.getLogger(SuggestionDaoImpl.class);
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public Map<String, Object> insert(String user_id, String content,
			String contacts,String deviceType,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Suggestion suggestion=new Suggestion(user_id, content, contacts,deviceType);
			mongoTemplate.insert(suggestion);
			map.put("code", "0");
			LoggerUtil.backlogsSuccess(logs, logger);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	
	
}
